package org.example.treehole.controller;

import org.example.treehole.pojo.dto.CardDto;
import org.example.treehole.pojo.entity.Card;
import org.example.treehole.pojo.other.PageBean;
import org.example.treehole.service.CardService;
import org.example.treehole.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/tree-hole")
public class CardController {
    @Autowired
    private CardService cardService;

    @PostMapping("/postcard")
    public Result postCard(@RequestBody CardDto cardDto){
        cardService.postCard(cardDto);
        return Result.success();
    }

    @GetMapping("/query-card")
    public Result allCard(){
        List<Card> cards = cardService.selectAllCard();
        return Result.success(cards);
    }

    @GetMapping("/page-card")
    public Result pageCard(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "5")Integer pageSize){PageBean pageBean = cardService.pageCard(page,pageSize);
        return Result.success(pageBean);
    }
}
